package com.neaten.functionArrangement.util;

import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

@Slf4j
@UtilityClass
public class FileUtil {
    /**
     * 文件移动
     *
     * @param targetPath
     * @param file
     */
    public static void moveFile(String targetPath, File file) {
        FileInputStream is = null;
        FileOutputStream os = null;
        try {
            is = new FileInputStream(file);
            File newFile = new File(targetPath);
            os = new FileOutputStream(newFile);
            int length = 0;
            byte[] buffer = new byte[1024 * 1024];
            while ((length = is.read(buffer)) != -1) {
                os.write(buffer, 0, length);
            }
        } catch (Exception e) {
        } finally {
            try {
                is.close();
                os.flush();
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        file.delete();
    }
}
